<?php  
import('miho.controller.event.ActionControllerEvent');
import('miho.controller.Controller');
import('miho.view.View');
/**
* 
*/
class ActionController
{
    protected $_view;
    protected $_vars = array();
    protected $_application;
    protected $_name;
    public function setName($value){
      $this->_name = $value;
    }
    public function getName(){
      return $this->_name;
    }
    
    public function __construct(){
      $this->_view = View::getInstance();
    }
    
    public function __get($name){
      return isset($this->_vars[$name]) ? $this->_vars[$name] : null;
    }
    
    public function __set($name,$value){
      $this->_vars[$name] = $value;
      var_dump($this->_vars);
    }
    
    public function getVars(){
      return $this->_vars;
    }
    
    public function getView(){
      return $this->_view;
    }
    
    public function execute($action){
      $actionName = $action;
      $action = 'execute'.ucfirst($action);
      $this->dispatchEvent(new ActionControllerEvent(ActionControllerEvent::PRE_EXECUTE,$this,$actionName));
      if(method_exists($this,$action)){
        $executeResult = $this->{$action}();
        if($executeResult==null){
          $executeResult='Success';
        }
      }else{
        throw new Exception('Action ' . $actionName . 'not found');
      }
      $this->dispatchEvent(new ActionControllerEvent(ActionControllerEvent::POST_EXECUTE,$this,$actionName,array('executeResult'=>$executeResult)));
    }
    
    public function dispatchEvent($event){
      Controller::getInstance()->dispatchEvent($event);
    }
    
    public static function getController(){
      
    }
    
}


?>